package Chapter9;
import java.awt.event.*;
import javax.swing.*;
public class Example22 extends JFrame {
	public Example22() {
		JMenuBar menuBar=new JMenuBar();
		this.setJMenuBar(menuBar);
		JMenu menu=new JMenu("操作");
		menuBar.add(menu);
		JMenuItem item1=new JMenuItem("弹出窗口");
		JMenuItem item2=new JMenuItem("关闭");
		item1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				JDialog dialog=new JDialog(Example22.this,true);
				dialog.setTitle("弹出窗口");
				dialog.setSize(200,200);
				dialog.setLocation(50, 50);
				dialog.setVisible(true);
			}
		});
		item2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		menu.add(item1);
		menu.addSeparator();
		menu.add(item2);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(300, 300);
		this.setVisible(true);
	}
	public static void main(String[] args) {
		new Example22();
	}
}
